<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="../../js/bootstrap-treegrid/css/bootstrap.css"
          rel="stylesheet" type="text/css"/>
    <link href="../../js/bootstrap-treegrid/css/bootstrap-table.css"
          rel="stylesheet" type="text/css"/>
    <link href="../../layui/theme/default/layer.css" rel="stylesheet"
          type="text/css"/>
    <link href="../../css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link href="../../css/H-ui.admin.css" rel="stylesheet" type="text/css"/>
    <link href="../../lib/icheck/icheck.css" rel="stylesheet"
          type="text/css"/>
    <head>
        <meta charset="utf-8">
        <title>设备管理</title>
    </head>

<body>
<div class="panel-body">
    <div class="tab-content">
        <div id="tab-4" class="tab-pane active">
            <table class="tablelg" width="100%">
                <tr>
                    <td width="90%">
                        <div class="row">
                            <div class="col-sm-12">
                                <form id="frm" method="post">
                                    <table width="100%" class="table table-bordered"
                                           style="margin-bottom: 5px; font-size: 12px;">
                                        <tbody>
                                        <tr>
                                        </tr>
                                        <tr>
                                        </tr>
                                        </tbody>
                                    </table>
                                </form>
                                <table id="cusTable2" style="table-layout: fixed;">
                                </table>
                                <div id="cusTable_tools">
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../layui/layer.js"></script>
<script type="text/javascript"
        src="../../js/bootstrap-treegrid/js/bootstrap.js"></script>
<script type="text/javascript"
        src="../../js/bootstrap-treegrid/js/bootstrap-table.js"></script>
<script type="text/javascript"
        src="../../js/bootstrap-treegrid/js/bootstrap-table-zh-CN.js"></script>
<script>
    $(function () {
        page_list2();
    });


    //查询2
    function page_list2() {
        $("#cusTable2").bootstrapTable('destroy');
        $('#cusTable2')
            .bootstrapTable(
                {
                    url: "../../../../../device/pageSoilRecord",
                    dataType: "json",
                    pagination: true, //分页
                    striped: true, //是否显示行间隔色
                    singleSelect: false,
                    sidePagination: "server", //服务端处理分页
                    toolbar: '#cusTable_tools',
                    pageNumber: 1, //初始化加载第一页，默认第一页
                    pageSize: 50,
                    height: 700, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    pageList: [50, 100, 500, 1000, 2000, 5000],
                    showColumns: true, //是否显示所有的列
                    showRefresh: true, //是否显示刷新按钮
                    clickToSelect: false, //是否启用点击选中行
                    queryParamsType: "limit",
                    queryParams: function queryParams(params) { //设置查询参数
                        var param = {
                            pageSize: params.limit,
                            pageIndex: params.offset
                        };
                        return param;
                    },
                    columns: [
                        {
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: '采集id',
                            align: "center"
                        },
                        {
                            field: 'name',
                            title: '设备名称',
                            align: "center"
                        },
                        {
                            field: 'deviceSn',
                            title: '设备号',
                            align: "center"
                        },
                        {
                            field: 'type',
                            title: '设备类型',
                            align: "center",
                            formatter: function (value, row,
                                                 index) {
                                if (value == "soil"){
                                    return"土壤检测设备";
                                }
                                return "摄像头设备";
                            }
                        },
                        {
                            field: 'value',
                            title: '数据'
                        },
                        {
                            field: 'unit',
                            title: '数据单位'
                        },
                        {
                            field: 'createTime',
                            title: '采集时间',
                            align: "center"
                        },
                        {
                            field: 'time',
                            title: '数据时间',
                            align: "center"
                        },
                        {
                            field: 'userType',
                            title: '操作',
                            align: "center",
                            formatter: function (value, row,
                                                 index) {
                                var strJoin = "";
                                strJoin += '<a href="#"><button type="button" onclick="deleteUser(' + row.id + ')" class="btn btn-danger">删除</button></a>&nbsp;&nbsp;';
                                return strJoin;
                            }
                        }]
                });
    }

    function addOpen() {
        layer.open({
            type : 2,
            title : '新增大棚',
            shadeClose : true,
            shade : 0.8,
            center : true,
            area : [ '91%', '91%' ],
            content : 'add/device_add.html' //iframe的url
        });
    }

    function deleteUser(id) {
        layer.msg('您确定要删除该大棚吗？', {
            time: 0 //不自动关闭
            ,
            btn: ['确认', '取消'],
            yes: function (index) {
                layer.close(index);
                $.ajax({
                    traditional: true,
                    url: "../../../../../device/delete?id=" + id,
                    data: {},
                    dataType: "text",
                    type: "get",
                    success: function (data) {
                        if (data == "success") {
                            layer.alert('删除成功！', {
                                icon: 6
                            }, function () {
                                window.location.reload();
                            });
                        } else {
                            layer.alert('删除失败！', {
                                icon: 5
                            });
                        }
                    }
                });
            }
        });
    }

    // 获取url参数
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return unescape(r[2]);
        return null;
    }


</script>
</body>

</html>